// 判断是否是美信应用
function isMission () {
  return window.navigator.userAgent.toLowerCase().indexOf('mideaconnect') > -1
}

// 判断是否是ios
function isIOS () {
  const u = navigator.userAgent
  return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
}

// 判断是否是Android
function isAndroid () {
  const u = navigator.userAgent
  return u.indexOf('Android') > -1 || u.indexOf('Adr') > -1
}

// 获取IOS版本
function getIosVersion () {
  let version = null
  if (isIOS()) {
    const ua = navigator.userAgent.toLowerCase()
    const reg = /os [\d._]+/gi
    const info = ua.match(reg)
    version = (info + '').replace(/[^0-9|_.]/ig, '').replace(/_/ig, '.')
    version = parseInt(version.split('.')[0])
  }
  return version
}

// 获取安卓版本
function getAndroidVersion () {
  let version = null
  if (isAndroid()) {
    var ua = navigator.userAgent.toLowerCase()
    var reg = /android [\d._]+/gi
    var info = ua.match(reg)
    version = (info + '').replace(/[^0-9|_.]/ig, '').replace(/_/ig, '.')
    version = parseInt(version.split('.')[0])
  }
  return version
}

export default {
  isMission,
  isIOS,
  isAndroid,
  getIosVersion,
  getAndroidVersion
}
